import nunjucks from 'nunjucks'
import { fileURLToPath } from 'url'

let fn_list = async (ctx, next) => {
  // let viewsBaseUrl = new URL('../views/blogs.html', import.meta.url)
  // let viewsBasePath = fileURLToPath(viewsBaseUrl.href)
  // console.log(viewsBasePath);

  // // 配置nunjucks  存放目录
  // let env = nunjucks.configure({ noCache: true, watch: true })
  // // 将文件和对象传递给nunjucks，发送客户端
  // ctx.body = env.render(viewsBasePath, {})
  ctx.body = '11'
}
let fn_getById = async (ctx, next) => {
  ctx.body = '单个图书'
}
let fn_add = async (ctx, next) => {
  ctx.body = '新增图书'
}
let fn_update = async (ctx, next) => {
  let id = ctx.params.id;
  ctx.body = '修改图书'
}
let fn_del = async (ctx, next) => {
  ctx.body = '删除某个图书'
}


export const obj = {
  'get /books': fn_list,
  'get /books/:id': fn_getById,
  'post /books': fn_add,
  'put /books/:id': fn_update,
  'delete /books/:id': fn_del
}